
/**
 * 只查找一条，如果有多条只返回第一条
 * @param array_data 数组型数据
 * @param conditions 条件
 */
ArrayData.exists = function(array_data, conditions){
    for (var i=0; i<array_data.length; i++){
        var line = array_data[i];
        var accord = true;
        for(var key  in conditions){
            if(!line[key] || line[key] != conditions[key]){
                accord = false;
                break;
            }
        }
        if(accord){
            return true;
        }
    }
    return false;
};

/**
 * 只查找一条，如果有多条只返回第一条
 * @param array_data 数组型数据
 * @param conditions 条件
 */
ArrayData.findOne = function(array_data, conditions){
    for (var i=0; i<array_data.length; i++){
        var line = array_data[i];
        var accord = true;
        for(var key in conditions){
            if(!line[key] || line[key] != conditions[key]){
                accord = false;
                break;
            }
        }
        if(accord){
            return line;
        }
    }
    return null;
};

ArrayData.find = function(array_data, conditions){
    var found = [];
    for (var i=0; i<array_data.length; i++){
        var line = array_data[i];
        var accord = true;
        for(var key in conditions){
            if(!line[key] || line[key] != conditions[key]){
                accord = false;
                break;
            }
        }
        if(accord){
            found.push(line);
        }
    }
    return found;
};

/**
 * 删除，无返回
 * @param array_data
 * @param conditions
 */
ArrayData.remove = function(array_data, conditions){
    for (var i=0; i<array_data.length; i++){
        var line = array_data[i];
        var accord = true;
        for(var key  in conditions){
            if(!line[key] || line[key] != conditions[key]){
                accord = false;
                break;
            }
        }
        if(accord){
            array_data.splice(i, 1);
        }
    }
};